<template>
  <div id="cluereport">
    <el-dialog
      :title="dialogTitle"
      :visible.sync="formShowVisible"
      width="98%" top="20px" :close-on-click-modal="false" :close-on-press-escape="false">
      <formShow :currentUnitname="unitname" :projectId="projectId" :timestamp="timestamp" :readOnly="readonly" :item="item" :unitDataDetail="unitDataDetail" @addData="addData"></formShow>
    </el-dialog>
    <el-dialog
      title="查看纪检机构信息"
      :visible.sync="unitInfoVisible"
      width="98%" top="20px" :close-on-click-modal="false" :close-on-press-escape="false">
      <unitFormShow :projectId="projectId" :timestamp="timestamp" :readOnly="readonly" @saveUnitData="saveUnitData" :unitData="unitData" />
    </el-dialog>
    <el-breadcrumb separator=">">
      <el-breadcrumb-item :to="{ path: '/' }">系统首页</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/supervision' }">干部监督统计</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/supervision/unitList/'+ project.id}">{{project.projectTitle}}</el-breadcrumb-item>
      <el-breadcrumb-item>查看</el-breadcrumb-item>
    </el-breadcrumb>
    <section class="wboxs">
    <!--工具条-->
      <h1>单位名称：{{unitname}}</h1>
      <el-button type="primary" @click="backUnit"  icon="el-icon-back" style="float:right;margin:10px 5px;">返回</el-button>
      <div style="line-height:200%;margin:10px;">姓名：{{unitDataDetail.realname}}
      </div>
    </section>
    <section class="unitbox" style="margin-top:10px">
    <!-- <section style="margin-top:10px"> -->
      <!--列表-->
      <el-table :data="list" highlight-current-row v-loading="listLoading" style="width: 100%;" :height="tableHeight" border
        ref="multipleTable"
        >
        <el-table-column type="index" label="序号" width="50" align="center" class-name="tableth" fixed="left">
        </el-table-column>
        <el-table-column label="因私出国（境）情况" prop="classified" align="center">
          <el-table-column label="涉密等级" width="50" prop="classified" align="center">
            <template slot-scope="scope">
              {{scope.row.reportItemJson.classified}}
            </template>
          </el-table-column>
          <el-table-column label="事由" width="50" prop="reason" align="center">
            <template slot-scope="scope">
              {{scope.row.reportItemJson.reason}}
            </template>
          </el-table-column>
          <el-table-column label="国家/地区" prop="region" width="90" align="center" show-overflow-tooltip>
            <template slot-scope="scope">
              {{scope.row.reportItemJson.region}}
            </template>
          </el-table-column>
          <el-table-column label="往返时间/出国（境）时间" prop="tripdate" width="190" align="center">
            <template slot-scope="scope">
              {{formatDate8(scope.row.reportItemJson.tripdate.split('-')[0])}} 至
              {{formatDate8(scope.row.reportItemJson.tripdate.split('-')[1])}}
            </template>
          </el-table-column>
          <el-table-column label="本年度实际出国（境）次数" prop="times" width="95" align="center">
            <template slot-scope="scope">
              {{scope.row.reportItemJson.times}}
            </template>
          </el-table-column>
          <el-table-column label="审批人姓名职务" prop="approver" width="80" align="center" show-overflow-tooltip>
            <template slot-scope="scope">
              {{scope.row.reportItemJson.approver}}
            </template>
          </el-table-column>
          <el-table-column label="是否持因私证件办理公务" prop="whether1" width="80" align="center">
            <template slot-scope="scope">
              {{scope.row.reportItemJson.whether1}}
            </template>
          </el-table-column>
          <el-table-column label="是否公款报销费用" prop="whether2" width="70" align="center">
            <template slot-scope="scope">
              {{scope.row.reportItemJson.whether2}}
            </template>
          </el-table-column>
          <el-table-column label="是否遇到策反等异常" prop="whether3" width="70" align="center">
            <template slot-scope="scope">
              {{scope.row.reportItemJson.whether3}}
            </template>
          </el-table-column>
          <el-table-column label="是否存在擅自出国（境）、超期未归、公款报销费用、泄露国家秘密等违规问题" prop="whether4" width="120" align="center">
            <template slot-scope="scope">
              {{scope.row.reportItemJson.whether4}}
            </template>
          </el-table-column>
          <el-table-column label="返回后证件是否按时交集中保管" prop="whether5" width="80" align="center">
            <template slot-scope="scope">
              {{scope.row.reportItemJson.whether5}}
            </template>
          </el-table-column>
          <el-table-column label="涉密人员出行前是否进行风险研判" prop="whether6" width="80" align="center">
            <template slot-scope="scope">
              {{scope.row.reportItemJson.whether6}}
            </template>
          </el-table-column>
          <el-table-column label="涉密人员出行前是否清退涉密载体，并对所携带智能设备安全检测" prop="whether7" width="130" align="center">
            <template slot-scope="scope">
              {{scope.row.reportItemJson.whether7}}
            </template>
          </el-table-column>
          <el-table-column label="涉密人员是否填写回访表" prop="whether8" width="120" align="center">
            <template slot-scope="scope">
              {{scope.row.reportItemJson.whether8}}
            </template>
          </el-table-column>
          <el-table-column label="证件状态" prop="status" width="80" align="center">
            <template slot-scope="scope">
              {{scope.row.reportItemJson.status}}
            </template>
          </el-table-column>
          <el-table-column label="备注" prop="remarks" width="60" align="center" show-overflow-tooltip>
            <template slot-scope="scope">
              {{scope.row.reportItemJson.remarks}}
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="违规情况" prop="description" align="center">
          <el-table-column label="违规情况简述" prop="description" align="center" show-overflow-tooltip>
            <template slot-scope="scope">
              {{scope.row.reportItemJson.description}}
            </template>
          </el-table-column>
          <el-table-column label="调查处理结果" prop="result" width="110" align="center" show-overflow-tooltip>
            <template slot-scope="scope">
              {{scope.row.reportItemJson.result}}
            </template>
          </el-table-column>
          <el-table-column label="备注" prop="violationremarks" width="60" align="center" show-overflow-tooltip>
            <template slot-scope="scope">
              {{scope.row.reportItemJson.violationremarks}}
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="操作" width="100" align="center" fixed="right">
          <template slot-scope="scope">
            <el-button @click="edit(scope.$index,scope.row)" type="primary" size="mini" style="margin:10px 0">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination :total="totalnum" :page-size="pageSize" @current-change="handleCurrentChange" :current-page="pageNum" @size-change="handleSizeChange" :page-sizes="[10, 20, 30, 50]" layout="total, sizes, prev, pager, next, jumper"></el-pagination>
      </div>
    </section>
  </div>
</template>

<script>
import formShow from './customFormShow'
import unitFormShow from './customUnitFormShow'
export default {
  components: {
    formShow, unitFormShow
  },
  data () {
    return {
      unitData: {},
      unitDataDetail: {},
      unitInfoVisible: false,
      total: 0,
      pageNum: 1,
      pageSize: 20,
      totalnum: 0,
      Isace: true,
      Sortkey: '',
      index: -1,
      formShowVisible: false,
      timestamp: '',
      unitId: null,
      deptId: null,
      projectId: null,
      dialogTitle: '查看',
      items: [],
      unitname: '',
      project: {},
      listLoading: true,
      dataLoading: true,
      tableHeight: 100,
      list: [
      ],
      changeSizeFlag: false,
      readonly: true,
      item: {},
      fileIds: []
    }
  },
  methods: {
    formatDate8 (str) {
      return str.slice(0, 4) + '-' + str.slice(4, 6) + '-' + str.slice(6, 8)
    },
    backUnit () {
      this.$router.push('/supervision/customUnitProjectDetail/' + this.unitId)
    },
    handleSizeChange (val) {
      this.changeSizeFlag = true
      this.pageNum = 1
      this.pageSize = val
      this.getProjectDataDetail(this.unitId)
    },
    handleCurrentChange (val) {
      if (this.changeSizeFlag === false) {
        this.pageNum = val
        this.getProjectDataDetail(this.unitId)
      }
    },
    saveUnitData () {
    },
    addData (item) {
      this.formShowVisible = false
      this.fileIds = []
      Object.keys(item).forEach(key => {
        JSON.parse(this.project.reportTemplate).columns.find(tempitem => { // 从模板中找出模板项为该key的配置项
          if (tempitem.title === key && tempitem.type === 'upload') { // 并且该配置项为文件类型
            if (item[key].length > 0) {
              this.fileIds = [...this.fileIds, ...item[key].map(files => files.id)]
            }
          }
        })
      })
      let para = {
        dataJson: item,
        fileIds: this.fileIds,
        projectDataId: parseInt(this.unitId),
        ageDate: '20250630'
      }
      this.$http
        .post(this.$http.defaults.unitReportAPI + `api/project/saveDataItem2025`, para)
        .then(response => {
          if (response.data.success) {
            this.fileIds = []
            this.$message({
              message: '保存成功',
              type: 'success'
            })
          } else {
            this.$message({
              message: '保存失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          this.$message({
            message: '网络保存失败:' + error,
            type: 'error'
          })
        })
    },
    showUnitInfo () {
      this.timestamp = new Date().getTime()
      this.unitInfoVisible = true
    },
    edit (index, item) {
      this.index = index
      this.timestamp = new Date().getTime()
      this.formShowVisible = true
      this.item = item
    },
    getProjectDetail (id) {
      this.dataLoading = true
      this.listLoading = true
      this.$http
        .get(this.$http.defaults.supervisionAPI + `api/statsProjectData/getById?id=` + id)
        .then(response => {
          this.project = response.data.result
          this.dataLoading = false
          this.listLoading = false
        })
        .catch(error => {
          this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
          this.dataLoading = false
          this.listLoading = false
        })
    },
    getProjectDataDetail (id) {
      this.$http
        .get(this.$http.defaults.supervisionAPI + `api/statsReportData/getById?id=` + id)
        .then(response => {
          this.unitname = response.data.result.unitName
          this.projectId = response.data.result.projectId
          this.getProjectDetail(this.projectId)
          this.getList(id)
          if (response.data.result.reportJson) {
            this.unitData = response.data.result.reportJson.list
            this.unitDataDetail = this.unitData.find(item => item.id === this.deptId)
          }
        })
        .catch(error => {
          this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
        })
    },
    getList (id) {
      let para = {
        reportDataId: id,
        orderField: this.Sortkey,
        orderType: this.Isace,
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        deptId: this.deptId
      }
      this.$http
        .post(this.$http.defaults.supervisionAPI + `api/statsReportDataItem/queryByPage`, para)
        .then(response => {
          this.listLoading = false
          this.list = response.data.result.records
          this.totalnum = response.data.result.total
          this.changeSizeFlag = false
        })
        .catch(error => {
          this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
        })
    },
    tableresize (obj) {
      var clientHeight = 0
      if (document.body.clientHeight && document.documentElement.clientHeight) {
        clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      } else {
        clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      }
      let myheight = 295

      obj.$nextTick(function () {
        obj.tableHeight = clientHeight - myheight
      })
    }
  },
  mounted () {
    this.unitId = parseInt(this.$route.params.id.split(',')[0])
    this.deptId = this.$route.params.id.split(',')[1]
    this.getProjectDataDetail(this.unitId)
    this.tableresize(this)
    window.onresize = () => {
      this.tableresize(this)
    }
  }
}
</script>
<style>
#cluereport .el-drawer__wrapper{
  width: 100%;
  height: 100%;
  position: fixed !important;
  overflow: hidden;
}
  .unitbox .el-table th{
    font-weight: normal;
    background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
  }
  .unitbox .el-table td, .el-table th{
    padding:0;
    font-size:var(--size14) !important;
    line-height: 20px;
    font-family: '宋体'
  }
  .tableth{
    background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
    height:33px;
  }
  #testlist .wboxs{
    height:45px;
    padding-top:10px;
  }
  #cluereport .el-table td{
    border-right: 1px solid #95B8E7;
    border-bottom: 1px solid #95B8E7;
  }
</style>
<style scoped>
  #cluereport .el-button{
    color:#fff !important;
  }
  #cluereport h1{
    font-size:var(--size16) !important;
    font-weight: bolder;
    height: 30px;
    border-bottom: 1px solid #95B8E7;
    font-family: '宋体';
    line-height: 30px;
    color: #000;
    padding-left:10px;
    background-image: linear-gradient(to bottom , #EEF4FF, #E0ECFF);
    margin:0;
  }
  .el-pagination{
    float: left;
    padding:7px 10px;
  }
  #cluereport .wboxs{
    width: 100%;
    background: #fff;
    border: 1px solid #95B8E7;
    margin:0 10px;
    overflow: hidden;
    padding:0;
  }
  .unitbox{
    padding:0;
    width: calc(100% - 0px);
    background: #fff;
    border: 1px solid #95B8E7;
    margin:0 10px;
    overflow: hidden;
  }
</style>
